package com.kxmall.admin.controller.vehicle;

import java.util.List;
import java.util.Arrays;

import cn.dev33.satoken.annotation.SaIgnore;
import com.kxmall.common.core.page.TableDataInfo;
import com.kxmall.vehicle.domain.bo.KxVehicleBo;
import com.kxmall.vehicle.domain.vo.KxVehicleBoxGoodsVo;
import com.kxmall.vehicle.domain.vo.KxVehicleVo;
import com.kxmall.admin.controller.vehicle.service.IKxVehicleManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.kxmall.common.annotation.RepeatSubmit;
import com.kxmall.common.annotation.Log;
import com.kxmall.common.core.controller.BaseController;
import com.kxmall.common.core.domain.PageQuery;
import com.kxmall.common.core.domain.R;
import com.kxmall.common.core.validate.AddGroup;
import com.kxmall.common.core.validate.EditGroup;
import com.kxmall.common.enums.BusinessType;
import com.kxmall.common.utils.poi.ExcelUtil;

/**
 * 餐车管理
 */
@Slf4j
@Api(tags = "餐车管理")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/vehicle/manage")
public class KxVehicleManageController extends BaseController {

    private final IKxVehicleManageService iKxVehicleManageService;

    /**
     * 查询全部餐车列表
     */
    @SaIgnore
    @ApiOperation(value = "/vehicle/manage/listAll - 查询全部餐车列表（全部）", httpMethod = "GET")
    @GetMapping("/listAll")
    public R<List<KxVehicleVo>> listAll(KxVehicleBo bo) {
        List<KxVehicleVo> list = iKxVehicleManageService.queryList(bo);
        log.info(list.toString());
        return R.ok(list);
    }
    /**
     * 导出餐车管理列表
     */
    @SaCheckPermission("vehicle:manage:export")
    @Log(title = "导出餐车管理列表", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "/vehicle/manage/export - 导出餐车管理列表", httpMethod = "POST")
    @PostMapping("/export")
    public void export(KxVehicleBo bo, HttpServletResponse response) {
        List<KxVehicleVo> list = iKxVehicleManageService.queryList(bo);
        log.info(list.toString());
        ExcelUtil.exportExcel(list, "餐车管理", KxVehicleVo.class, response);
    }
    /**
     * 分页查询餐车列表
     */
    @SaCheckPermission("vehicle:manage:pageList")
    @ApiOperation(value = "/vehicle/manage/pageList - 分页查询餐车列表", httpMethod = "GET")
    @GetMapping("/pageList")
    public TableDataInfo<KxVehicleVo> pageList(KxVehicleBo bo, PageQuery pageQuery) {
        TableDataInfo<KxVehicleVo> infoList = iKxVehicleManageService.queryPageList(bo, pageQuery);
        log.info(infoList.toString());
        return infoList;
    }
    /**
     * 获取餐车管理详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("vehicle:manage:query")
    @ApiOperation(value = "/vehicle/manage/query/{id} - 获取餐车管理详细信息", httpMethod = "GET")
    @GetMapping("/query/{id}")
    public R<KxVehicleVo> query(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        KxVehicleVo kxVehicleVo = iKxVehicleManageService.queryById(id);
        log.info(kxVehicleVo.toString());
        return R.ok(kxVehicleVo);
    }
    /**
     * 新增餐车管理
     */
    @SaCheckPermission("vehicle:manage:add")
    @Log(title = "新增餐车管理", businessType = BusinessType.INSERT)
    @ApiOperation(value = "/vehicle/manage/add - 新增餐车管理", httpMethod = "POST")
    @PostMapping("/add")
    @RepeatSubmit()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody KxVehicleBo bo) {
        return toAjax(iKxVehicleManageService.insertByBo(bo));
    }
    /**
     * 修改餐车管理
     */
    @SaCheckPermission("vehicle:manage:edit")
    @Log(title = "修改餐车管理", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "/vehicle/manage/edit - 修改餐车管理", httpMethod = "PUT")
    @PutMapping("/edit")
    @RepeatSubmit()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody KxVehicleBo bo) {
        return toAjax(iKxVehicleManageService.updateByBo(bo));
    }
    /**
     * 删除餐车管理
     *
     * @param ids 主键串
     */
    @SaCheckPermission("vehicle:manage:remove")
    @Log(title = "删除餐车管理", businessType = BusinessType.DELETE)
    @ApiOperation(value = "/vehicle/manage/remove/{ids} - 删除餐车管理", httpMethod = "DELETE")
    @DeleteMapping("/remove/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iKxVehicleManageService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 餐车状态批量更新为正常
     */
    @ApiOperation(value = "/vehicle/manage/updateVehicleStateToNormal - 餐车状态批量更新为正常", httpMethod = "POST")
    @PostMapping("/updateVehicleStateToNormal")
    public R<Boolean> updateVehicleStateToNormal(@RequestBody KxVehicleBo bo){
       return R.ok(iKxVehicleManageService.updateVehicleStateToNormal(bo));
    }

    /**
     * 餐车状态批量更新为禁用
     */
    @ApiOperation(value = "/vehicle/manage/updateVehicleStateToAbort - 餐车状态批量更新为禁用", httpMethod = "POST")
    @PostMapping("/updateVehicleStateToAbort")
    public R<Boolean> updateVehicleStateToAbort(@RequestBody KxVehicleBo bo){
       return R.ok(iKxVehicleManageService.updateVehicleStateToAbort(bo));
    }

    /**
     * 餐车营业状态批量更新为营业中
     */
    @ApiOperation(value = "/vehicle/manage/updateBusinessStateToOpen - 餐车营业状态批量更新为营业中", httpMethod = "POST")
    @PostMapping("/updateBusinessStateToOpen")
    public R<Boolean> updateBusinessStateToOpen(@RequestBody KxVehicleBo bo){
        return R.ok(iKxVehicleManageService.updateBusinessStateToOpen(bo));
    }

    /**
     * 餐车营业状态批量更新为休息中
     */
    @ApiOperation(value = "/vehicle/manage/updateBusinessStateToRest - 餐车营业状态批量更新为休息中", httpMethod = "POST")
    @PostMapping("/updateBusinessStateToRest")
    public R<Boolean> updateBusinessStateToRest(@RequestBody KxVehicleBo bo){
        return R.ok(iKxVehicleManageService.updateBusinessStateToRest(bo));
    }



    /**
     * 餐车营业状态批量更新为休息中
     */
//    @PostMapping("/options")
//    @ApiOperation(value = "/vehicle/manage/options - 餐车营业状态批量更新为休息中", httpMethod = "POST")
//    public R<List<KxVehicleVo>> options(){
//        return R.ok(iKxVehicleManageService.options());
//    }

    /**
     * 获取指定餐车的二维码
     */
    @PostMapping("/getVehicleQrcodeImage")
    @ApiOperation(value = "/vehicle/manage/getVehicleQrcodeImage - 获取指定餐车的二维码", httpMethod = "POST")
    public R<String> getVehicleQrcodeImage(){
        return R.ok(iKxVehicleManageService.getVehicleQrcodeImage());
    }

    /**
     * 打印测试
     */
//    @PostMapping("/printTest")
//    @ApiOperation(value = "/vehicle/manage/printTest - 打印测试", httpMethod = "POST")
//    public R<Boolean> printTest(@RequestBody KxVehicleBo bo){
//        return R.ok(iKxVehicleManageService.printTest(bo));
//    }


}
